package com.china08.yxyapi.api.manage.tec.teaching.lecture.teachreport;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.esbag.YxyEsbagTeachingPerformance;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.esbag.YxyEsbagTeachingPerformanceRepository;

/**
 * 老师 ---备授课--授课报告-课堂表现--修改学生表现
 * 
 */
@CrossOrigin
@RestController
public class LectureReportClassPerformanceUptController extends YxyApiBaseController {

    @Autowired
    private YxyEsbagTeachingPerformanceRepository yxyEsbagTeachingPerformanceRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/lecture/performance/class/upd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel) {

        String packId = reqModel.packId;
        String classId = reqModel.classId;
        String studentId = reqModel.studentId;
        Assert.notNull(StringUtils.defaultIfBlank(packId, null), "授课包ID为空");
        String userId = getProfile(request, response).getId();
        String schoolId = getProfile(request, response).getSchoolId();
        Integer status = reqModel.status;

        YxyEsbagTeachingPerformance perform = yxyEsbagTeachingPerformanceRepository
                .findBySchoolIdAndTeacherIdAndStudentIdAndClassIdAndPackId(schoolId, userId, studentId, classId,
                        packId);
        perform.setPerformance(status);
        yxyEsbagTeachingPerformanceRepository.save(perform);
        RespModel model = new RespModel();
        model.setMessage("修改成功");
        return model;
    }

    protected static class ReqModel extends YxyApiPageReqModel {
        // 班级ID
        public String classId;
        // 授课包ID
        public String packId;
        // 学生ID
        public String studentId;
        // 表现状态 0--正常 1--表扬 2--批评 3--缺勤
        public Integer status;
    }

    protected static class RespModel extends YxyApiRespModel {

    }
}
